package webrtc

import (
	"encoding/json"
	"sync"
	"time"

	"github.com/fasthttp/websocket"
	"github.com/pion/webrtc/v3"
)

const (
	writeWait      = 10 * time.Second
	pongWait       = 60 * time.Second
	pingPeriod     = (pongWait * 9) / 10
	maxMessageSize = 8192
)

var (
	newline = []byte{'\n'}
	space   = []byte{' '}
)

var upgrader = websocket.FastHTTPUpgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
}

var (
	ClientLock sync.RWMutex
	// ClientMap  map[int]*Client
)

const (
	SDP         = "sdp"
	ICE         = "ice"
	BYE         = "bye"
	JOIN        = "join"
	FEEDBACK    = "feedback"
	OPERATE     = "opr"
	OPRCALLBACK = "oprcallback"
	ORIENTATION = "orientation"
	INFOIVCODE  = "infoinvitecode"
	// REFRESHIVCODE = "refreshinvitecode"
)

type RecvMessage struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

type StringMessage struct {
	Type string `json:"type"`
	Data string `json:"data"`
	Code int    `json:"code"`
}

type SendMessage struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

type RotationEvent struct {
	Rotation int `json:"rotation"`
	Width    int `json:"width"`
	Height   int `json:"height"`
}

type SDPMessage webrtc.SessionDescription

type ICEMessage webrtc.ICECandidateInit

// type Response
